using Front._1120;
using MySqlConnector;

namespace Front;

public partial class userservice : Form
{
    string account;
    string password;
    string pwd;
    public userservice()
    {
        InitializeComponent();
    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        throw new System.NotImplementedException();
    }

    private void Form1_Load(object sender, EventArgs e)
    {//这里用来切面使用！！！

    }

    private void button1_Click(object sender, EventArgs e)
    {
        using var connection = new MySqlConnection("Server=localhost;port=3306;user=root;password=123456#;Database=book");
        connection.Open();
        string sql = "SELECT * FROM admin_info where admin_account = @account and admin_password = @password";
        using var command = new MySqlCommand(sql , connection);
        //
        account = textBox1.Text;
        password = textBox2.Text;
        pwd = MD5Helper.GetMD5(password);
        //get meta
        command.Parameters.AddWithValue("account", account);
        command.Parameters.AddWithValue("password", pwd);
        using var reader = command.ExecuteReader();

        if (reader.HasRows)
        {
            MainForm mainForm = new MainForm();
            mainForm.Show();
            this.Hide();
        }
        else
        {
            MessageBox.Show("账号或密码错误！");
        }
        // while (reader.Read())
        // {
        //     richTextBox1.AppendText(reader.GetInt32(0) + Environment.NewLine);   // 或 GetInt32(0)
        // }


        // MessageBox.Show("SciAwe");
        // Form2 f2 = new Form2();
        // f2.ShowDialog();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    }

    private void label2_Click(object sender, EventArgs e)
    {
    }
}